import { Excel } from '@ttou/midway-excel'
import { Exclude } from 'class-transformer'

import {
  SysDeptEntity,
  SysPostEntity,
  SysRoleEntity,
  SysUserEntity
} from '@/entity'

/**
 * 用户模板序列化
 */
export class UserTemplateSerialize implements SysUserEntity {
  userId: string
  deptId: string

  @Excel({ header: '用户账号', key: 'userName' })
  userName: string

  @Excel({ header: '用户昵称', key: 'nickName' })
  nickName: string

  @Excel({ header: '邮箱', key: 'email' })
  email: string

  @Excel({ header: '手机', key: 'phone' })
  phone: string

  @Excel({ header: '性别', key: 'sex' })
  sex: string

  avatar: string

  @Excel({ header: '密码', key: 'password' })
  password: string

  status: string
  delFlag: string
  loginIp: string
  loginDate: Date
  createBy: string
  createTime: Date
  updateBy: string
  updateTime: Date

  @Excel({ header: '备注', key: 'remark' })
  remark: string

  dept: SysDeptEntity
  roles: SysRoleEntity[]
  posts: SysPostEntity[]
}

/**
 * 用户导出序列化
 */
export class UserExportSerialize implements SysUserEntity {
  @Excel({ header: '用户编号' })
  userId: string

  @Exclude()
  deptId: string

  @Excel({ header: '用户账号' })
  userName: string

  @Excel({ header: '用户昵称' })
  nickName: string

  @Excel({ header: '邮箱' })
  email: string

  @Excel({ header: '手机' })
  phone: string

  @Excel({ header: '性别' })
  sex: string

  @Exclude()
  avatar: string

  @Exclude()
  password: string

  @Excel({ header: '状态' })
  status: string

  @Exclude()
  delFlag: string

  @Excel({ header: '最后登录IP' })
  loginIp: string

  @Excel({ header: '最后登录时间' })
  loginDate: Date

  @Excel({ header: '创建者' })
  createBy: string

  @Excel({ header: '创建时间' })
  createTime: Date

  @Excel({ header: '更新者' })
  updateBy: string

  @Excel({ header: '更新时间' })
  updateTime: Date

  @Excel({ header: '备注' })
  remark: string

  @Exclude()
  dept: SysDeptEntity

  @Exclude()
  roles: SysRoleEntity[]

  @Exclude()
  posts: SysPostEntity[]

  constructor(partial: any) {
    Object.assign(this, partial)
  }
}
